import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

const router = new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: [
  {
    path: '/PCchatInterface',
    component: resolve => require(['@/pages/PCchatInterface/PCchatInterface'], resolve)
  },

  {
    path: '/customerConsultation',
    component: resolve => require(['@/pages/customerConsultation/customerConsultation'], resolve)
  },
  {
    path: '/login',
    component: resolve => require(['@/pages/login/login'], resolve)
  },
  ]
})


router.beforeEach((to, from, next) => {
  //打印来的路径和去的路径

  //对于登录页面不拦截
  if (to.path == '/login') {
    // 接下来的函数
    next();
  } else {
    //var会将作用域放大，let只是局部的作用域
    let token = localStorage.getItem('CustomerToken');
    //用户访问认证后页面时 必须校验用户信息是否存在，不存在去登陆页
    if (!token||token==undefined) {
      // this.$message.error("登录已过期，请先登录");
      next('/login');
    } else {
      next();
    }
  }
});

export default router
